package com.ruoyi.profession.controller;

import java.security.SecureRandom;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.profession.domain.InvitationList;
import com.ruoyi.profession.service.IInvitationListService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * appuserController
 *
 * @author ruoyi
 * @date 2024-06-14
 */
@RestController
@RequestMapping("/profession/list")
public class InvitationListController extends BaseController
{
    @Autowired
    private IInvitationListService invitationListService;

    /**
     * 查询appuser列表
     */
    @PreAuthorize("@ss.hasPermi('profession:list:list')")
    @GetMapping("/list")
    public TableDataInfo list(InvitationList invitationList)
    {
        startPage();
        List<InvitationList> list = invitationListService.selectInvitationListList(invitationList);
        return getDataTable(list);
    }

    /**
     * 导出appuser列表
     */
    @PreAuthorize("@ss.hasPermi('profession:list:export')")
    @Log(title = "appuser", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InvitationList invitationList)
    {
        List<InvitationList> list = invitationListService.selectInvitationListList(invitationList);
        ExcelUtil<InvitationList> util = new ExcelUtil<InvitationList>(InvitationList.class);
        util.exportExcel(response, list, "appuser数据");
    }

    /**
     * 获取appuser详细信息
     */
    @PreAuthorize("@ss.hasPermi('profession:list:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(invitationListService.selectInvitationListById(id));
    }

    /**
     * 新增appuser
     */
    @PreAuthorize("@ss.hasPermi('profession:list:add')")
    @Log(title = "appuser", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InvitationList invitationList)
    {
        return toAjax(invitationListService.insertInvitationList(invitationList));
    }

    /**
     * 修改appuser
     */
    @PreAuthorize("@ss.hasPermi('profession:list:edit')")
    @Log(title = "appuser", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InvitationList invitationList)
    {
        return toAjax(invitationListService.updateInvitationList(invitationList));
    }

    /**
     * 删除appuser
     */
    @PreAuthorize("@ss.hasPermi('profession:list:remove')")
    @Log(title = "appuser", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(invitationListService.deleteInvitationListByIds(ids));
    }
    /**
     * 返回code邀请码
     */
    @PreAuthorize("@ss.hasPermi('profession:list:list')")
    @GetMapping("/addCode")
    public AjaxResult addCode(){
        Random RANDOM = new SecureRandom();
        String SYMBOLS = "0123456789";
        char[] nonceChars = new char[6];  //指定长度，自己可以设置

        for (int index = 0; index < nonceChars.length; ++index) {
            nonceChars[index] =  SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
        }
        Map<String,Object> result=new HashMap<>() ;
        result.put("code",nonceChars);
        return AjaxResult.success(result);
    }
}

